<?php
declare(strict_types=1);

namespace App\Controller;

use App\Service\UserService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Contract\RequestInterface;

/**
 * @Controller()
 * Class DemoController
 * @package App\Controller
 */
class DemoController extends AbstractController {
    /**
     * @Inject()
     * @var UserService
     */
    private $userService;

    /**
     * @RequestMapping(path="index", methods={"get","post"})
     */
    public function index(RequestInterface $request){
        $method = $this->request->getMethod();
        $id = $request->input('id', 1);
        return [
            'id'=>$id,
            'method'=>$method,
            'msg'=>date('Y-m-d H:i:s')
        ];
    }

    /**
     * @RequestMapping(path="gu", methods={"get"})
     */
    public function getUser(RequestInterface $request){
        $id = $request->input('id', 1);
        $data = $this->userService->getInfoById($id);
        return [
            'id'=>$id,
            'data'=>$data
        ];
    }
}